<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class NotificationsApiController extends AbstractRestfulController
{
    public function getList()
    {
		header('Access-Control-Allow-Origin: *');
		
    }
    public function get($id)
    {	
		header('Access-Control-Allow-Origin: *');
    }
    public function create($oder)
    {
		header('Access-Control-Allow-Origin: *');
		$orderDeliveryTable=$this->getServiceLocator()->get('Models\Model\OrderDeliveryDetailsFactory');
		
			$getOrderDetails = $orderDeliveryTable->assignOrdersToShops($oder);
			if(count($getOrderDetails)!=0){
			return new JsonModel(array(
				'shop_order_ids'	=>	json_encode($getOrderDetails),
				'success'		=> 	'success',
			));
			}else{
				return new JsonModel(array(
					'status'		=> 'not success',
				));
			}
    }
    public function update($orderId,$order)
    {
		header('Access-Control-Allow-Origin: *');
		$orderDeliveryTable=$this->getServiceLocator()->get('Models\Model\OrderDeliveryDetailsFactory');
		if(isset($order['admin_confirm']) && $order['admin_confirm']=='1')
		{
			$result = $orderDeliveryTable->updateShopOrdersByAdmin($order);
			if(count($result)!=0){
			
				return new JsonModel(array(
					'status'			=>	"1",
				));
			
		}else{
			return new JsonModel(array(
				'status'			=>	'Fail',
			));
		}
		}else{
		$result = $orderDeliveryTable->updateOderWithQutation($orderId,$order);
		if($result!=0){
			
				return new JsonModel(array(
					'status'			=>	$result,
				));
			
		}else{
			return new JsonModel(array(
				'status'			=>	'Fail',
			));
		}
		}
    }
    public function delete($id)
    {
       
    }
}